<div id="Merging-a-branch"></div>
<div class="header">
<p>
Next: [[cvs: Merging from a branch several times#Merging from a branch several times|Merging more than once]], Previous: [[cvs: Magic branch numbers#Magic branch numbers|Magic branch numbers]], Up: [[cvs: Branching and merging#Branching and merging|Branching and merging]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>

----

<div id="Merging-an-entire-branch"></div>
=== Merging an entire branch ===
<div id="index-Merging-a-branch"></div>
<div id="index-_002dj-_0028merging-branches_0029"></div>

You can merge changes made on a branch into your working copy by giving
the &lsquo;<code>-j <var>branchname</var></code>&rsquo; flag to the <code>update</code> subcommand.  With one
&lsquo;<code>-j <var>branchname</var></code>&rsquo; option it merges the changes made between the
greatest common ancestor (GCA) of the branch and the destination revision (in
the simple case below the GCA is the point where the branch forked) and the
newest revision on that branch into your working copy.

<div id="index-Join"></div>
The &lsquo;<code>-j</code>&rsquo; stands for &ldquo;join&rdquo;.

<div id="index-Branch-merge-example"></div>
<div id="index-Example_002c-branch-merge"></div>
<div id="index-Merge_002c-branch-example"></div>
Consider this revision tree:

<div class="example" style="margin-left: 3.2em">
 +-----+    +-----+    +-----+    +-----+
 ! 1.1 !----! 1.2 !----! 1.3 !----! 1.4 !      &lt;- The main trunk
 +-----+    +-----+    +-----+    +-----+
                 !
                 !
                 !   +---------+    +---------+
 Branch R1fix -&gt; +---! 1.2.2.1 !----! 1.2.2.2 !
                     +---------+    +---------+
</div>

The branch 1.2.2 has been given the tag (symbolic name) &lsquo;<code>R1fix</code>&rsquo;.  The
following example assumes that the module &lsquo;<code>mod</code>&rsquo; contains only one
file, &lsquo;<tt>m.c</tt>&rsquo;.

<div class="example" style="margin-left: 3.2em">
 $ cvs checkout mod               # <span class="roman" style="font-family:serif; font-weight:normal">Retrieve the latest revision, 1.4</span>
 
 $ cvs update -j R1fix m.c        # <span class="roman" style="font-family:serif; font-weight:normal">Merge all changes made on the branch,</span>
                                  # <span class="roman" style="font-family:serif; font-weight:normal">i.e. the changes between revision 1.2</span>
                                  # <span class="roman" style="font-family:serif; font-weight:normal">and 1.2.2.2, into your working copy</span>
                                  # <span class="roman" style="font-family:serif; font-weight:normal">of the file.</span>
 
 $ cvs commit -m &quot;Included R1fix&quot; # <span class="roman" style="font-family:serif; font-weight:normal">Create revision 1.5.</span>
</div>

A conflict can result from a merge operation.  If that
happens, you should resolve it before committing the
new revision.  See [[cvs: Conflicts example#Conflicts example|Conflicts example]].

If your source files contain keywords (see [[cvs: Keyword substitution#Keyword substitution|Keyword substitution]]),
you might be getting more conflicts than strictly necessary.  See
[[cvs: Merging and keywords#Merging and keywords|Merging and keywords]], for information on how to avoid this.

The <code>checkout</code> command also supports the &lsquo;<code>-j <var>branchname</var></code>&rsquo; flag.  The
same effect as above could be achieved with this:

<div class="example" style="margin-left: 3.2em">
 $ cvs checkout -j R1fix mod
 $ cvs commit -m &quot;Included R1fix&quot;
</div>

It should be noted that <code>update -j <var>tagname</var></code> will also work but may
not produce the desired result.  See [[cvs: Merging can add or remove files#Merging can add or remove files|Merging adds and removals]], for more.


----

<div class="header">
<p>
Next: [[cvs: Merging from a branch several times#Merging from a branch several times|Merging more than once]], Previous: [[cvs: Magic branch numbers#Magic branch numbers|Magic branch numbers]], Up: [[cvs: Branching and merging#Branching and merging|Branching and merging]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>
This document was generated on <i>a sunny day</i> using [http://www.nongnu.org/texi2html/ <i>texi2html</i>].
